package com.bwie.gddproject.regist.view;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.bwie.gddproject.R;
import com.bwie.gddproject.base.BaseActivity;
import com.bwie.gddproject.index.view.IndexActivity;
import com.bwie.gddproject.regist.preccenter.RegistPresenter;

public class RegistActivity extends BaseActivity implements View.OnClickListener,IRegistActivity {

    private ImageView mBack;
    /**
     * 手机号
     */
    private EditText mEtPhone;
    /**
     * 请输入密码
     */
    private EditText mEtPwd;
    private ImageView mIvPwd;
    /**
     * 注册
     */
    private Button mBtRegist;
    private LinearLayout mActivityLogin;
    private RegistPresenter registPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        initView();
    }


    private void initView() {
        mBack = (ImageView) findViewById(R.id.back);
        mBack.setOnClickListener(this);
        mEtPhone = (EditText) findViewById(R.id.et_phone);
        mEtPwd = (EditText) findViewById(R.id.et_pwd);
        mIvPwd = (ImageView) findViewById(R.id.iv_pwd);
        mBtRegist = (Button) findViewById(R.id.bt_regist);
        mBtRegist.setOnClickListener(this);
        mActivityLogin = (LinearLayout) findViewById(R.id.activity_login);
        registPresenter = new RegistPresenter(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.back:
                finishThis();
                break;
            case R.id.bt_regist:
                registPresenter.regist();
                break;
        }
    }

    @Override
    public String getAccount() {
        return mEtPhone.getText().toString().trim();
    }

    @Override
    public String getPwd() {
        return mEtPwd.getText().toString().trim();
    }

    @Override
    public void show(String str) {
        Toast.makeText(this,str, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void toRegisterAc() {
        Intent intent = new Intent(this,RegistActivity.class);
        startActivity(intent);
    }

    @Override
    public void toIndexAc() {
        Intent intent = new Intent(this,IndexActivity.class);
        startActivity(intent);
    }
    public void finishThis(){
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        Log.e("tag",getAccount()+"");
        bundle.putString("mobile", getAccount());//添加要返回给页面1的数据
        bundle.putString("password",getPwd());//添加要返回给页面1的数据
        intent.putExtras(bundle);
        setResult(2, intent);//返回值调用函数，其中2为resultCode，返回值的标志
        finish();//传值结束
    }
}
